% 测试基的正交性
clear; close all; clc;
bases = cell(6,1);
% 定义基函数，确保所有运算都是元素级的
syms x y;
bases{1} = 1;
bases{2} =  sqrt(2)* (x - 1/3);
bases{3} = (sqrt(2)/2)* (x - 1/3) + sqrt(2)* (y - 1/3);
bases{4} = -1/9 - (4/15) * (x - 1/3) + 2 * (x - 1/3)^2;
bases{5} =(2/15) * (x - 1/3) + (4/15) * (y - 1/3) + (x - 1/3)^2 + 2 * (x - 1/3) * (y - 1/3);
bases{6} = -2/27 + (2/9) * (x - 1/3) + (1/3) * (x - 1/3)^2 + 2 * (x - 1/3) * (y - 1/3) + 2 * (y - 1/3)^2;
integrate = @(f) int(int(f, y, 0, 1-x), x, 0, 1);
for i = 1:6
    for j = 1:i
        % 关键修正：用元素乘法 .* 确保输出尺寸与输入匹配
        ortho = double(integrate(bases{i}*bases{j}));
        fprintf('∫v%d*v%d dxdy = %.6f  ', i-1, j-1, ortho);
    end
    fprintf('\n');
end